<div class="content-wrapper">
    <section class="content-header">
        <h1>
            公共客户列表
        </h1>
        <ol class="breadcrumb">
            <li><a href="/admin"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">客户管理</li>
            <li class="active">客户列表</li>
        </ol>
    </section>
    <section class="content">
        <div class="box">
            <div class="box-header with-border">
                <form class="form-inline" action="/admin/customer/commonCustomerList" method="get">
                    <div class="form-group">
                        <label for="type">类别 </label>
                        <select class="form-control" name="type" id="type">
                            <option value="-1">选择类别</option>
                            <foreach name="typeList" item="type" key="key">
                                <option value="{$key}" <if condition="$key eq $type">selected</if>>{$type}</option>
                            </foreach>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="company_name">公司名称 </label>
                        <input type="text" class="form-control" id="company_name" name="company_name" placeholder="输入公司名" value="{$company_name}">
                    </div>
                    <div class="form-group">
                        <label for="company_name">录入人 </label>
                        <input type="text" class="form-control" id="admin_name" name="admin_name" placeholder="录入人" value="{$admin_name}">
                    </div>
                    <div class="form-group">
                        <label for="phase">阶段 </label>
                        <select class="form-control" name="phase" id="phase">
                            <option value="-1">选择阶段</option>
                            <foreach name="phaseList" item="phase_val" key="phase_key">
                                <option value="{$phase_key}" <if condition="$phase_key eq $phase">selected</if>>{$phase_val}</option>
                            </foreach>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="department_id">部门 </label>
                        <select class="form-control" name="department_id" id="department_id">
                            <option value="-1">选择部门</option>
                            <foreach name="departmentList" item="department">
                                <option value="{$department.id}" <if condition="$department.id eq $department_id">selected</if>>{$department.name}</option>
                            </foreach>
                        </select>
                    </div>
                    <button type="submit" class="btn btn-info" id="save-btn">查询</button>&nbsp;
                </form>
                <div class="nav-search" id="nav-search">
                    <ul class="list-inline">
                        <li class="pull-right"><button id="btn-change-admin" class="btn bg-maroon btn-md" type="button">转单</button></li>
                    </ul>
                </div>
            </div>
            <div class="box-body table-responsive">
                <table class="table table-bordered">
                    <tbody>
                    <tr>
                        <th style="width:25px;">
                            <label>
                                <input type="checkbox" class="ace" name="allid" id="allid">
                                <span class="lbl">
                                    </span>
                            </label>
                        </th>
                        <th style="width: 40px">ID</th>
                        <th>公司名称</th>
                        <th>客户姓名</th>
                        <th>客户手机号</th>
                        <th>推广产品</th>
                        <th>一级分类</th>
                        <th>二级分类</th>
                        <th>类别</th>
                        <th>级别</th>
                        <th>录入人</th>
                        <th>部门</th>
                        <th>状态</th>
                        <th>阶段</th>
                        <th>录入时间</th>
                        <th>更新时间</th>
                        <th>掉入库时间</th>
                        <th>操作</th>
                    </tr>
                    <if condition="count($customerList) eq 0"><tr><td class="text-center" colspan="14">暂无数据...</td></tr></if>
                    <foreach name="customerList" item="customer">
                            <tr>
                                <td>
                                   <label>
                                       <input type="checkbox" class="ace"
                                              name="ids"
                                              value="{$customer.id}"
                                              data-admin="{$customer.admin_id}"
                                       >
                                       <span class="lbl">
                                           </span>
                                   </label>
                               </td>
                                <td>{$customer.id}</td>
                                <td>{$customer.company_name}</td>
                                <td>{$customer.name}</td>
                                <td>{$customer.mobile}</td>
                                <td>{$customer.product_name}</td>
                                <td>{$customer.first_name}</td>
                                <td>{$customer.second_name}</td>
                                <td>{$customer.type_desc}</td>
                                <td>{$customer.level_desc}</td>
                                <td>{$customer.admin_name}</td>
                                <td>{$customer.department_name}</td>
                                <td>
                                    <if condition="$customer.status eq 1">
                                            <span class="label label-success">{$customer.status_desc}</span>
                                        <elseif condition="$customer.status eq 5" />
                                            <span class="label label-danger refuse-detail" data-detail="{$customer.refuse_reason}" onclick="show_reason(this)">{$customer.status_desc}</span>
                                        <elseif condition="$customer.status eq 10" />
                                            <span class="label label-warning">{$customer.status_desc}</span>
                                        <else />
                                            <span class="label label-primary">{$customer.status_desc}</span>
                                    </if>
                                </td>
                                <td>{$customer.phase_desc}</td>
                                <td>{$customer.create_time}</td>
                                <td>{$customer.update_time}</td>
                                <td>{$customer.archive_time}</td>
                                <td>
                                    <button class="btn btn-primary btn-xs" type="button" onclick="window.location.href='/admin/customer/yzAuditingEditCustomer?id={$customer.id}'">详情</button>&nbsp;
                                </td>
                            </tr>
                        </foreach>
                    </tbody>
                </table>
            </div>
            <div class="box-footer clearfix">{$page_html}</div>
        </div>
    </section>
</div>
<!--modal-->
<div class="modal fade" tabindex="-1" role="dialog" id="change-admin">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">转单操作</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="JavaScript:;" method="POST">
                    <div class="form-group">
                        <label for="s_department_id" class="col-md-2 control-label">部门 </label>
                        <div class="col-md-8">
                            <select class="form-control" name="s_department_id" id="s_department_id">
                                <option value="0">请选择</option>
                                <foreach name="departmentList" item="s_department">
                                    <option value="{$s_department.id}">{$s_department.name}</option>
                                </foreach>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="admin_id" class="col-md-2 control-label">部门人员 </label>
                        <div class="col-md-8">
                            <select class="form-control" name="admin_id" id="admin_id">
                                <option value="-1">请选择</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" id="change-btn" class="btn btn-primary">确认</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script src="__PUBLIC__/AdminLTE/plugins/layer/layer.js"></script>
<script type="text/javascript">
    function show_reason(obj) {
        var reason = $(obj).attr('data-detail');
        if(!reason){
           reason = "无拒绝原因";
        }
        layer.alert(reason, {
            skin: 'layui-layer-lan'
            ,closeBtn: 0
            ,anim: 4 //动画类型
        });
    }
    $("#s_department_id").change(function () {
        var department_id = $(this).val();
        console.info(department_id);
        if(department_id==0 || isNaN(department_id)){
            layer.tips('请选择部门', '#s_department_id', {
                tips: [3, '#0FA6D8'], //设置tips方向和颜色 类型：Number/Array，默认：2 tips层的私有参数。支持上右下左四个方向，通过1-4进行方向设定。如tips: 3则表示在元素的下面出现。有时你还可能会定义一些颜色，可以设定tips: [1, '#c00']
                tipsMore: false, //是否允许多个tips 类型：Boolean，默认：false 允许多个意味着不会销毁之前的tips层。通过tipsMore: true开启
                time:1000  //2秒后销毁，还有其他的基础参数可以设置。。。。这里就不添加了
            });
            return false;
        }
        $.post('/admin/user/ajaxGetUserList',{
            department_id: department_id
        },function (_data) {
            var html = "<option value='0'>请选择</option>";
            if(_data.Code ==999){
                var userList = _data.Data.userList||[];
                $.each(userList,function (index,item) {
                    html += "<option value='"+item.id+"'>"+item.name+"</option>"
                });
            }else{
                layer.msg(_data.Msg,{time:1000});
                return false;
            }
            $("#admin_id").html(html);
        },'JSON');
    });
    /**
     * 保存
     */
    $("#btn-change-admin").click(function () {

        var chooseList = [];//选中
        $('input[name=ids]:checked').each(function(){
            var item = {};
            var id = $(this).val();
            var admin_id = $(this).attr('data-admin');

            item.id = id;
            item.admin_id = admin_id;
            chooseList.push(item);
        });
        if(chooseList.length == 0) {
            layer.msg("请选择要操作的客户");
            return false;
        }
        $("#change-admin").modal('show');
        $("#change-btn").click(function () {
            var department_id = $("#s_department_id").val();
            var admin_id = $("#admin_id").val();

            if(department_id==0 || isNaN(department_id)){
                layer.tips('请选择部门', '#s_department_id', {
                    tips: [3, '#0FA6D8'], //设置tips方向和颜色 类型：Number/Array，默认：2 tips层的私有参数。支持上右下左四个方向，通过1-4进行方向设定。如tips: 3则表示在元素的下面出现。有时你还可能会定义一些颜色，可以设定tips: [1, '#c00']
                    tipsMore: false, //是否允许多个tips 类型：Boolean，默认：false 允许多个意味着不会销毁之前的tips层。通过tipsMore: true开启
                    time:1000  //2秒后销毁，还有其他的基础参数可以设置。。。。这里就不添加了
                });
                return false;
            }
            if(admin_id==0 || isNaN(admin_id)){
                layer.tips('请选择部门人员', '#admin_id', {
                    tips: [3, '#0FA6D8'], //设置tips方向和颜色 类型：Number/Array，默认：2 tips层的私有参数。支持上右下左四个方向，通过1-4进行方向设定。如tips: 3则表示在元素的下面出现。有时你还可能会定义一些颜色，可以设定tips: [1, '#c00']
                    tipsMore: false, //是否允许多个tips 类型：Boolean，默认：false 允许多个意味着不会销毁之前的tips层。通过tipsMore: true开启
                    time:1000  //2秒后销毁，还有其他的基础参数可以设置。。。。这里就不添加了
                });
                return false;
            }
            $("#change-admin").modal('hide');
            layer.load(1,{shade: [0.8, '#393D49']});
            $.post('/admin/customer/ajaxChangeCustomerOrder',{
                department_id: department_id,
                admin_id: admin_id,
                chooseList: chooseList
            },function (_data) {
                layer.closeAll('loading');
                if(_data.Code==999){
                    layer.msg("操作成功",{time:1000});
                    window.location.reload(true);
                }else {
                    window.showinfo('提示', _data.Msg);
                    return false;
                }
            },"JSON");
        });
    });
    $(function () {
        //全选
        $('#allid').click(function() {
            var ischecked = $(this).prop('checked');
            $('input[name=ids]').prop("checked", !!ischecked);
        });
    });
</script>